//
//  JSListHelper.h
//  JSBasicFramework
//
//  Created by Apple on 2018/8/2.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <YTKNetwork.h>

@class JSListHelper;

typedef NS_ENUM(NSUInteger, JSListStyle) {
    CollectionStyle,
    TableViewStyle,
};

typedef NS_ENUM(NSUInteger, ListRefreshStyle) {
    MJ_RefreshStyle,
    Kaka_RefreshStyle,
};
typedef NS_ENUM(NSUInteger, ListRefrehState) {
    ListRefreshStateAll,
    ListRefreshStateHeader,
    ListRefreshStateFooter,
};


typedef void (^ListViewRefresh)(JSListHelper *helper, id owner);
/** 获取每组HeaderIdentifer */
typedef NSString *(^HeaderIdentifer)(id list,NSInteger section);
/** 获取每组FooterIdentifer */
typedef NSString *(^FooterIdentifer)(id list,NSInteger section);
/** 获取CellIdentifer */
typedef NSString *(^CellIdentifer)(id list,NSIndexPath *indexPath);
/** fd */
typedef NSArray <NSString *> *(^SectionIndexTitlesForTableView)(id list);
/** 注册 头尾视图 */
typedef void (^RegisterWithIdentifer)(id list);

/*!
 设置size
 
 如果列表是TableView 只取高度
 */
typedef CGSize (^CellWithSize)(id list, NSIndexPath *indexPath);
/** 每组头部size */
typedef CGSize (^HeaderWithSize)(id list,NSInteger section);
/** 每组尾部size */
typedef CGSize (^FooterWithSize)(id list,NSInteger section);

typedef NSInteger (^RowNumber)(id list, NSInteger section);
typedef NSInteger (^SectionNumber)(id list);

/*!
 数据处理
 
 数据给外部控制
 */
typedef void (^CellConfigData)(id cell, NSIndexPath *indexPath);
typedef void (^HeaderConfigData)(id headerView, NSInteger section);
typedef void (^FooterConfigData)(id footerView, NSInteger section);

typedef void (^DidSelectIndexPath)(id list, NSIndexPath *indexPath);


#pragma mark - 空页面处理
/**
 返回标题文字
 */
typedef NSAttributedString *(^EmptyDataTitle)(UIScrollView *owner);
/**
 空页面占位图
 */
typedef UIImage *(^EmptyDataImage)(UIScrollView *owner);
/**
 返回详情文字
 */
typedef NSAttributedString *(^EmptyDataDetailTitle)(UIScrollView *owner);
/**
 返回文字按钮
 */
typedef NSAttributedString *(^EmptyDataButtonTitle)(UIScrollView *owner, UIControlState state);
/**
 返回图片按钮
 */
typedef UIImage *(^EmptyDataButtonImage)(UIScrollView *owner, UIControlState state);
/**
 自定义背景颜色
 */
typedef UIColor *(^EmptyDataBackColor)(UIScrollView *owner);
/**
 设置垂直偏移量
 */
typedef CGFloat (^EmptyDataVerticalOffSet)(UIScrollView *owner);
/**
 设置自定义视图
 */
typedef UIView *(^EmptyDataCustomView)(UIScrollView *owner);
/**
 设置垂直间距
 */
typedef CGFloat (^EmptyDataVerticalSpace)(UIScrollView *owner);
/**
 是否允许滚动
 */
typedef BOOL (^EmptyDataShouldAllScroll)(UIScrollView *owner);
/**
 按钮点击事件
 */
typedef void (^EmptyDataDidTapButton)(UIScrollView *owner);






@interface JSListHelper : NSObject<UITableViewDelegate,
UITableViewDataSource,
UICollectionViewDelegate,
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout,
DZNEmptyDataSetSource,
DZNEmptyDataSetDelegate
>

@property (nonatomic, weak) id owner;
@property (nonatomic, copy) RegisterWithIdentifer registerBefore;

@property (nonatomic, copy) CellIdentifer cellIdentifer;
@property (nonatomic, copy) HeaderIdentifer headerIdentifer;
@property (nonatomic, copy) FooterIdentifer footerIdentifer;

@property (nonatomic, copy) CellWithSize cellWithSize;
@property (nonatomic, copy) HeaderWithSize headerWithSize;
@property (nonatomic, copy) FooterWithSize footerWithSize;


@property (nonatomic, copy) SectionIndexTitlesForTableView indexTitlesForTableView;
@property (nonatomic, copy) RowNumber rowNumber;
@property (nonatomic, copy) SectionNumber sectionNumber;

@property (nonatomic, copy) CellConfigData cellConfig;
@property (nonatomic, copy) HeaderConfigData headerConfig;
@property (nonatomic, copy) FooterConfigData footerConfig;

@property (nonatomic, copy) DidSelectIndexPath didSelectIndexPath;

@property (nonatomic, copy) EmptyDataTitle emptyTitle;
@property (nonatomic, copy) EmptyDataDetailTitle emptyDetailTitle;
@property (nonatomic, copy) EmptyDataButtonTitle emptyButtonTitle;
@property (nonatomic, copy) EmptyDataButtonImage emptyButtonImage;
@property (nonatomic, copy) EmptyDataBackColor emptyBackColor;
@property (nonatomic, copy) EmptyDataVerticalOffSet emptyVerticalOfferSet;
@property (nonatomic, copy) EmptyDataCustomView emptyCustomView;
@property (nonatomic, copy) EmptyDataVerticalSpace emptyVerticatialSpace;
@property (nonatomic, copy) EmptyDataShouldAllScroll emptyShouldScroll;
@property (nonatomic, copy) EmptyDataDidTapButton emptyButtonTap;
@property (nonatomic, copy) EmptyDataImage emptyImage;

/*!
 设置刷新回调
 
 重写set方法设置和移除刷新控件 下拉刷新
 */
@property (nonatomic, copy) ListViewRefresh headerRefresh;
/*!
 设置刷新回调
 
 重写set方法设置和移除刷新控件 上拉加载更多
 */
@property (nonatomic, copy) ListViewRefresh footerRefresh;
/**
 * 通过一个请求类初始化刷新状态 如果需要关闭刷新 直接设置 footerRefresh 或者 headerRefresh 为nil即可
 * @param request 请求类
 * @param completion 请求成功的回调
 * @param faild 请求失败的回调
 */
-(void)setRefrenshWithRequest:(YTKRequest *)request
               withCompletion:(void(^)(id result, NSInteger curentPage))completion
                        error:(void(^)(NSError *))faild;

-(instancetype)initWithOwner:(id)owner
                     Regiter:(RegisterWithIdentifer) registerBefore
               sectionNumber:(SectionNumber)sectionNumber
                   rowNumber:(RowNumber)rowNumber
                 cellIdentifer:(CellIdentifer)cellIdentifer
               headerIdentifer:(HeaderIdentifer)headerIdentifer
               footerIdenrifer:(FooterIdentifer)footerIdentifer
                  cellWithSize:(CellWithSize)cellWithSize
                headerWithSize:(HeaderWithSize)headerWithSize
                footerWithSize:(FooterWithSize)footerWithSize
                  cellConfig:(CellConfigData)cellConfig
                headerConfig:(HeaderConfigData)headerConfig
                footerConfig:(FooterConfigData)footerConfig
          didSelectIndexPath:(DidSelectIndexPath)didSelectIndexPath;

-(void)reloadData;

-(instancetype)initializeEmptyData;
- (void)resetEmpatyData;
/**
 需要提前调用 initializeEmptyData 方法
 统一设置空页面
 */
-(void) settingEmptyDataTitle:(EmptyDataTitle)title
                    dataImage:(EmptyDataImage)image
                  detailTitle:(EmptyDataDetailTitle)detailTitle
                  buttonTitle:(EmptyDataButtonTitle)buttonTitle
                  buttonImage:(EmptyDataButtonImage)buttonImage
                    backColor:(EmptyDataBackColor)backColor
                       offSet:(EmptyDataVerticalOffSet)offSet
                   customView:(EmptyDataCustomView)customView
                verticalSpace:(EmptyDataVerticalSpace)verticalSpace
                 shouldScroll:(EmptyDataShouldAllScroll)sholdScroll
                    buttonTap:(EmptyDataDidTapButton)buttonTap;

// 1. 手动触发刷新
- (void)beginRefreshing:(ListRefrehState)refreshState;
/*
 一般方式结束刷新
 */
- (void)endRefreshing:(ListRefrehState)refreshState;

/*
 结束刷新且需要提示文字
 */
- (void)endRefreshingWithRefresh:(ListRefrehState)refreshState alertText:(NSString *)text completion:(dispatch_block_t)completion;

/*
 结束刷新且不再需要刷新功能
 */
- (void)endRefreshingAndNoLongerRefreshingWithAlertText:(NSString *)text;
/*
 重新恢复刷新
 */
- (void)resumeRefreshAvailable;
/// 不显示刷新状态 更新数据
- (void)loadData:(BOOL )isNew;
@end

@interface YTKRequest (Page)

@property (nonatomic, assign) NSInteger currentPage; // currentPage 必须有值 
@property (nonatomic, assign) NSInteger pageSize;

@end
